<?php

namespace app\api\controller;

use app\api\service\TokenService;
use app\common\model\User as UserModel;
use think\Controller;

class User extends Base
{
    public function decrypt()
    {
        $wechatApp = new \app\mpbase\library\WechatApp();
        $res = $wechatApp->decryptData();
        return self::apiResp($res);
    }

    public function login_code()
    {

        $wechatApp = new \app\mpbase\library\WechatApp();
        $sessionData = $wechatApp->code();
//        $sessionData = action('mpbase/WechatApp/code');
        $res = (new UserModel())->loginByOpenId($sessionData['openid']);
        return self::apiResp($res);
    }

    public function check()
    {
        $token = input('token');
        $check = (new TokenService())->check($token);
        $res = [
            'check' => $check,
            'msg' => $check ? '校验通过' : '校验失败',
        ];
        return self::apiResp($res);
    }
}
